ans = []
count = []
top = 0
s = input().split()
n = int(s[0])
m = int(s[1])

for i in range(0, n):
	ss = input().split()
	flag = False
	for j in range(0, top):
		if ans[j] == ss:
			flag = True
			count[j] = count[j] + 1
			break
	if flag == False:
		top = top + 1
		ans.append(ss)
		count.append(1)

for i in range(0, m):
	ss = input().split()
	flag = False
	for j in range(0, top):
		if ans[j] == ss:
			flag = True
			print(count[j])
			break
	if flag == False:
		print("Not Found!")
